package com.jqr.activity.jumpactivity01;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    private Button btnJumpOther;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnJumpOther=findViewById(R.id.btnJumpOther);

        btnJumpOther.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(MainActivity.this,OtherActivity.class);


                //1 跳转A->B
                // startActivity(intent);


                //2 跳转A->B 传参
                //Bundle bundle=new Bundle();
                //bundle.putString("other","jump to otherActivity");
                //startActivity(intent,bundle);

                //3 跳转A->B-A A跳转到B然后B把参数传数据给A
                int requestCode=1;
                startActivityForResult(intent,requestCode);

            }
        });

    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == 1) {
            if (resultCode == RESULT_OK) {

                if(data!=null){
                    String other=data.getStringExtra("other");
                }

            }
            else if (resultCode == RESULT_CANCELED) {
                Log.d("MainActivity", "onActivityResult: 返回数据已经取消");
            }
        }
    }

}